<template>
	<view class="page">
		<flowbefore :beflows="beflows" :status="status" :isBtnClick="isBtnClicks" @save="save" @submit="submit" :statusType='statusType'>
			<template>
				<view class="padding-bottom-100">
					<form class="flowform">
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>流程标题</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.flowTitle" name="flowTitle" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>单号编号</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.billNo" name="billNo" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="flowUrgent">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>紧急程度</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.flowUrgent" name="flowUrgent" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>申请人员</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.applyUser" name="applyUser" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>申请部门</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.applyDept" name="applyDept" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup">
								<view class="labletitle"><label>申请日期</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.applyDate" name="applyDate" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext margin-top-20">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>相关客户</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.customer" name="customer" placeholder="输入相关客户" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>相关项目</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.project" name="project" placeholder="输入相关项目" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>售前支持</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.psaleSupInfo" name="psaleSupInfo" placeholder="输入售前支持" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="startDate">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>开始时间</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.startDate" name="startDate" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="endDate">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>结束时间</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.endDate" naem="endDate" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>支持天数</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="number" v-model="salesSupport.psaleSupDays" name="psaleSupDays" maxlength="8" placeholder="输入支持天数" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>准备天数</label></view>
								<view class="controlvalue">
									<input type="number" v-model="salesSupport.psalePreDays" name="psalePreDays" maxlength="8" placeholder="输入准备天数" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>机构咨询</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.consulManager" name="consulManager" placeholder="输入机构咨询" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup">
								<view class="labletitle"><label>售前顾问</label></view>
								<view class="controlvalue">
									<input type="text" v-model="salesSupport.psalSupConsul" name="psalSupConsul" placeholder="输入售前顾问" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist margin-top-20">
							<view class="formgroup  padding-17 border-bottom-E3E3E5">
								<view class="labletitletar"><label>销售总结</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="salesSupport.salSupConclu" name="salSupConclu" :disabled="disabled" placeholder="输入"/>
								</view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup  padding-17 border-bottom-E3E3E5">
								<view class="labletitletar"><label>交付说明</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="salesSupport.consultResult" name="consultResult" :disabled="disabled" placeholder="输入"/>
								</view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup padding-17 border-bottom-E3E3E5">
								<view class="labletitletar"><label>咨询评价</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="salesSupport.ievaluation" name="ievaluation" :disabled="disabled" placeholder="输入"/>
								</view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup padding-17">
								<view class="labletitletar"><label>发起人总结</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="salesSupport.conclusion" name="conclusion" :disabled="disabled" placeholder="输入"/>
								</view>
							</view>
						</view>
						
						<JNPFUpload v-model="fileList" :fileSize='2' :limit='9'></JNPFUpload>
						
					</form>
					<view class="height-100"></view>
				</view>
			</template>
		</flowbefore>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
	</view>
</template>

<script>
	import jnpf from '@/common/js/jnpf.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	import wPicker from '@/components/w-picker/w-picker.vue'
	import flowbefore from '@/components/work/flow-before.vue'
	import config from '@/common/js/config.js'
	let formRule=[
			{name:"flowTitle",checkType:"notnull",checkRule:"",errorMsg:"输入标题"},
			{name:"customer",checkType:"notnull",checkRule:"",errorMsg:"输入相关客户"},
			{name:"project",checkType:"notnull",checkRule:"",errorMsg:"输入相关项目"},
			{name:"flowUrgent", checkType : "notnull", checkRule:"",  errorMsg:"选择紧急程度"},
			{name:"startDate", checkType : "notnull", checkRule:"",  errorMsg:"选择开始日期"},
			{name:"endDate", checkType : "notnull", checkRule:"",  errorMsg:"选择结束日期"},
			{name:"psaleSupDays", checkType : "int", checkRule:"0,8",  errorMsg:"支持天数应为1~8个字符"},
		];
	export default {
		components: {
			wPicker,
			flowbefore,
		},
		data() {
			return {
				mode:'',//底部弹窗分类
				isSearchShow:false,
				disabled:false,//启用
				status:'',//流程状态
				beflows:{
					operstate:"",
					processId:''
				},
				salesSupport:{
					billNo:'',
					flowUrgent:'',
					flowTitle:jnpf.userInfo().realName+'的销售支持表',
					applyDate: helper.toDate(new Date, 'yyyy-MM-dd'),
					applyDept:jnpf.userInfo().departmentName,
					applyUser:jnpf.userInfo().realName+"/"+jnpf.userInfo().account,
					startDate:'',
					endDate:'',
					fileJson:'',
					psaleSupDays:'',
					psalePreDays:'',
					customer:'',
					project:''
				},
				fileList:[],
				fileJson:[],
				isBtnClicks:false,
				pickerList:[],
				urgentList:[{
					label: "普通",
					value:"1"
				},
				{
					label: "重要",
					value:"2"
				},
				{
					label: "紧急",
					value:"3"
				}],
				statusType:''
			}
		},
		onLoad(e) {
			/* 工作区进入状态 */
			let statusType = uni.getStorageSync("type")
			this.statusType = statusType
			/* 工作区进入状态 End*/
			let flowInfo= JSON.parse(e.flowInfo);
			this.beflows.operstate=flowInfo.operstate;
			if(flowInfo.operstate =='add'){
				this.salesSupport.flowId=flowInfo.id;
				this.status = 0;
				this.salesSupport.flowUrgent=helper.getSpinnerNew(this.urgentList,'1');
				helper.ajax({
					url: '/api/System/BillRule/BillNumber/WF_SalesSupportNo',
					success: res => {
						this.salesSupport.billNo=res.data.data;
					}
				});
			}
			if(flowInfo.operstate=='info'){
				this.disabled=flowInfo.disabled;
				this.beflows.processId=flowInfo.id;
				this.status=flowInfo.status;
				helper.ajax({
					url: '/api/WorkFlowForm/SalesSupport/' + flowInfo.id,
					success: res => {
						let _salesSupport=res.data.data;
						this.salesSupport = _salesSupport;
						this.salesSupport.flowUrgent=helper.getSpinnerNew(this.urgentList,_salesSupport.flowUrgent);
						this.salesSupport.applyDate=helper.toDate(_salesSupport.applyDate, 'yyyy-MM-dd');
						this.salesSupport.startDate=helper.toDate(_salesSupport.startDate, "yyyy-MM-dd HH:mm");
						this.salesSupport.endDate=helper.toDate(_salesSupport.endDate, "yyyy-MM-dd HH:mm");
						if (_salesSupport.fleJson!="") {
							this.fileList=JSON.parse(_salesSupport.fleJson);
						}
					}
				});
			}
		},
		methods: {
			flowUrgent(e){
				if(!this.disabled){
					this.pickerList = this.urgentList;
					this.mode="selector";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.salesSupport.flowUrgent = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			startDate(e){
				if(!this.disabled){
					this.mode="dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.salesSupport.startDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			endDate(e){
				if(!this.disabled){
					this.mode="dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.salesSupport.endDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			submit(e){
				this.salesSupport.fileJson = JSON.stringify(this.fileList);
				let formData=this.salesSupport;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = 0;
				let method = "POST";
				let url = "/api/WorkFlowForm/SalesSupport";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.startDate = Date.parse(formData.startDate);
				formData.endDate = Date.parse(formData.endDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
			save(e){
				this.salesSupport.fileJson = JSON.stringify(this.fileList);
				let formData=this.salesSupport;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = 1;
				let method = "POST";
				let url = "/api/WorkFlowForm/SalesSupport";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.startDate = Date.parse(formData.startDate);
				formData.endDate = Date.parse(formData.endDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
			
		},
	}
</script>

<style>
	.required{
		color: red;
	}
</style>
